package per.zzzfwd.query;

public class QueryBuilder {

    // 基础表达式由 "字段" ":" "值" 组成
    //
    // 字段由 "前缀修饰词"(非必需) "字段名称" "后缀修饰词"(非必需) 组成
    //
    // 值由 "["或者"{"(左边界，对应大于等于或大于，非必需) "数字"或者"字符串" "AND"或者"OR"(非必需) "数字"或者"字符串"(非必需) "]"或者"}"(右边界，对应小于等于或小于，非必需) 组成
    //
    // 复合表达式由 "基础表达式"或者"复合表达式" "AND"或者"OR" "基础表达式"或者"复合表达式" 组成

    // Equal, NotEqual, Between, Like, NotLike, GreaterThan, GreaterThanOrEqualTo, LessThan, LessThanOrEqualTo
    // AND, OR

    public Predicate equal(String field, Object value) {
        return new ComparisonPredicate(
            ComparisonPredicate.ComparisonOperator.EQUAL,
            new FieldBuilder().field(field),
            new ValueBuilder().literal(value)
        );
    }

    public Predicate equal(String field, Object... values) {
        return new ComparisonPredicate(
            ComparisonPredicate.ComparisonOperator.EQUAL,
            new FieldBuilder().field(field),
            new ValueBuilder().list(values)
        );
    }

    public Predicate equal(String field, Value value) {
        return new ComparisonPredicate(
            ComparisonPredicate.ComparisonOperator.EQUAL,
            new FieldBuilder().field(field),
            value
        );
    }

    public Predicate equal(String field, Value... values) {
        return new ComparisonPredicate(
            ComparisonPredicate.ComparisonOperator.EQUAL,
            new FieldBuilder().field(field),
            new ValueBuilder().or(values)
        );
    }

    public Predicate notEqual(String field, Object... values) {
        return null;
    }

    public Predicate greaterThan(String field, Object minValue) {
        return new ComparisonPredicate(
            ComparisonPredicate.ComparisonOperator.GREATER_THAN,
            new FieldBuilder().field(field),
            new ValueBuilder().literal(minValue)
        );
    }

    public Predicate greaterThanOrEqualTo(String field, Object minValue) {
        return new ComparisonPredicate(
            ComparisonPredicate.ComparisonOperator.GREATER_THAN_OR_EQUAL,
            new FieldBuilder().field(field),
            new ValueBuilder().literal(minValue)
        );
    }

    public Predicate lessThan(String field, Object maxValue) {
        return new ComparisonPredicate(
            ComparisonPredicate.ComparisonOperator.LESS_THAN,
            new FieldBuilder().field(field),
            new ValueBuilder().literal(maxValue)
        );
    }

    public Predicate lessThanOrEqualTo(String field, Object maxValue) {
        return new ComparisonPredicate(
            ComparisonPredicate.ComparisonOperator.LESS_THAN_OR_EQUAL,
            new FieldBuilder().field(field),
            new ValueBuilder().literal(maxValue)
        );
    }

    public Predicate between(String field, Object minValue, Object maxValue) {
        return new BetweenPredicate(
            new FieldBuilder().field(field),
            new LiteralValue(minValue),
            new LiteralValue(maxValue)
        );
    }

    public Predicate like(String field, Object value) {
        return null;
    }

    public Predicate notLike(String field, Object value) {
        return null;
    }

    public Predicate and(Predicate... predicates) {
        return new CompoundPredicate(Predicate.PredicateConjunction.AND, predicates);
    }

    public Predicate or(Predicate... predicates) {
        return new CompoundPredicate(Predicate.PredicateConjunction.OR, predicates);
    }
}
